package com.lykj.llw.box.adapter.banner

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.github.chrisbanes.photoview.PhotoView
import com.lykj.lib_base.component.GlideApp
import com.youth.banner.adapter.BannerAdapter


/**
 * ================================================
 * 多图预览banner适配器
 * ================================================
 *
 * @author gosha
 * @date 2023/12/7-16:05
 */

/**
 * 自定义布局，下面是常见的图片样式，更多实现可以看demo，可以自己随意发挥
 */
class PreviewBannerAdapter(mData: List<String>) :
    BannerAdapter<String, PreviewBannerAdapter.BannerViewHolder?>(mData) {

    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val imageView = PhotoView(parent.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.FIT_CENTER
        return BannerViewHolder(imageView)
    }

    override fun onBindView(holder: BannerViewHolder?, data: String?, position: Int, size: Int) {
        GlideApp.with(holder?.itemView!!)
            .load(data)
            .transition(DrawableTransitionOptions.withCrossFade())
            .into(holder?.imageView!!)
    }


    inner class BannerViewHolder(var imageView: PhotoView) :
        RecyclerView.ViewHolder(
            imageView
        )
}

